import 'package:sgy_flutter/ble/base_service.dart';

class NameService extends BaseService {
  static const _nameServiceGuid = "00001800-0000-1000-8000-00805f9b34fb";
  static const _readCharacteristicGuid = "00002a00-0000-1000-8000-00805f9b34fb";

  NameService()
      : super(
            serviceGuid: _nameServiceGuid,
            characteristicNotifyGuid: null,
            characteristicReadGuid: _readCharacteristicGuid,
            characteristicWriteGuid: null);

  Future<String> readName() async {
    print("nameService readCharacteristic:$readCharacteristic");
    final list = await readCharacteristic?.read();
    var name = String.fromCharCodes(list ?? []);
    return name.isNotEmpty ? name : "${list?.map((e) => String.fromCharCode(e)).join()}";
  }
}
